<?php
namespace app\models;
use ac\component\tool\Tool;
use app\models\Basic;

use Yii;
use yii\helpers\Html;

class Star extends Basic
{
    
    public static function tableName()
    {
        return '{{%pj8_member_star}}';
    }

    public function rules()
    {
        return [
            ['member_id', 'required', 'message' => 'member_id不能为空', 'on' => 'add'],
            ['member_id', 'integer', 'message' => 'member_id必须为数字，或数字字符串', 
                         'min'=>1, 'tooSmall' => 'member_id最小存储1'],
            ['goods_id', 'required', 'message' => 'goods_id不能为空', 'on' => 'add'],
            ['goods_id', 'integer', 'message' => 'goods_id必须为数字，或数字字符串', 
                         'min'=>1, 'tooSmall' => 'goods_id最小存储1'],
            ['add_time', 'default', 'value' => '1000-01-01 00:00:00'],
            ['add_time', 'date', 'format'=>'yyyy-MM-dd HH:mm:ss', 'message' => 'add_time非yyyy-MM-dd HH:mm:ss格式'],
        ];
    }


    /*添加*/
    public function addStar($data)
    {
        // P($data);
        $this->scenario = 'add';
        // P($data);
        $data['Star']['add_time'] = date('Y-m-d H:i:s', time());
        if($this->load($data) and $this->validate()){
            // P($this);
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }


    public function getGoods()
    {
        $info = $this->hasOne(Goods::className(), ['goods_id' => 'goods_id'])
                    ->select(['{{%pj8_goods}}.goods_id', 'name', 'dynasty', 'preview']);
        return $info;
    }

    
}